package com.sc.mockweipo.config;

import org.springframework.amqp.core.AmqpAdmin;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.amqp.rabbit.core.RabbitManagementTemplate;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author sc
 * Created on  2017/12/22
 *
 * 基础配置
 */
@Configuration
public class BaseRabbitConfig {

    @Bean
    public ConnectionFactory connectionFactory(){
        CachingConnectionFactory factory = new CachingConnectionFactory();
        factory.setVirtualHost("/");
        factory.setUsername("用户名");
        factory.setPassword("密码");
        factory.setAddresses("地址");
        return factory;
    }
    @Bean
    public RabbitManagementTemplate rabbitManagementTemplate(){
        return new RabbitManagementTemplate("http://用户名:密码@地址/api/");
    }

    @Bean
    public AmqpAdmin amqpAdmin(){
        return new RabbitAdmin(connectionFactory());
    }

    @Bean
    public RabbitTemplate rabbitTemplate(){
        return new RabbitTemplate(connectionFactory());
    }
}
